package com.norriekoelle.virtualsensors.kinect;

/**
 * Commands recognised from the Kinect that may be handled by the app. 
 * 
 * Feed server message into here and switch over result for commands interested in.
 * 
 * @author norrielm
 *
 */
public class CommandInterface {

	public static enum commands {
		//app 
		HOTSPOT, 
		//user tracking update
		TRACKING_ON, TRACKING_OFF, LOST_USER, NEW_USER,
		//interactions
		SWIPE_UP, SWIPE_DOWN, SWIPE_L, SWIPE_R,
		PUSH,RAISE_HAND,CIRCLE,WAVE,SELECT,CLICK,
		//logging
		LOG_ON, LOG_OFF,
		//comms 
		ACK, CONNECT, EXIT, 
		//default
		UNDEFINED}; 
	
	public static CommandInterface.commands handleKinectMessage(String s){
		s = s.toLowerCase();
	
		//Exit
    	if(s==null || s.contains("exit"))
    		return CommandInterface.commands.EXIT;

		else if(s.contains("ack"))
			return CommandInterface.commands.ACK;	
    	
    	//Connection established
    	else if(s.contains("connect"))
    		return CommandInterface.commands.CONNECT;

		/* ******* */
    	
    	//Hand tracking update
		else if (s.contains("accel") && s.contains("on"))
			return CommandInterface.commands.TRACKING_ON;

		else if (s.contains("accel") && s.contains("off"))
			return CommandInterface.commands.TRACKING_OFF;
			
		//New user id: assigned id
		else if(s.contains("user") && s.contains("new"))
			return CommandInterface.commands.NEW_USER;
		
    	//Lost: remove id if it is our previously assigned one
		else if(s.contains("user") && s.contains("lost"))
			return CommandInterface.commands.LOST_USER;

		/* ******* */

    	//Log on
		else if(s.contains("log") && s.contains("on"))
			return CommandInterface.commands.LOG_ON;
    	
    	//Log on
		else if(s.contains("log") && s.contains("off"))
			return CommandInterface.commands.LOG_OFF;

		/* ******* */
		
    	//At a hotspot
    	else if(s.contains("hotspot"))
    		return CommandInterface.commands.HOTSPOT;

		/* ******* */
    	
    	//Interaction
    	else if(s.contains("swipe") && (s.contains("up")))
    		return CommandInterface.commands.SWIPE_UP;
    	else if(s.contains("swipe") && (s.contains("down")))
    		return CommandInterface.commands.SWIPE_DOWN;
    	else if(s.contains("swipe") && (s.contains("left")))
    		return CommandInterface.commands.SWIPE_L;
    	else if(s.contains("swipe") && (s.contains("right")))
    		return CommandInterface.commands.SWIPE_R;
    	else if(s.contains("push"))
    		return CommandInterface.commands.PUSH;
    	else if(s.contains("raise") && (s.contains("hand")))
    		return CommandInterface.commands.RAISE_HAND;	
    	else if(s.contains("circle"))
    		return CommandInterface.commands.CIRCLE;
    	else if(s.contains("wave"))
    		return CommandInterface.commands.WAVE;
    	else if(s.contains("select"))
    		return CommandInterface.commands.SELECT;
		
    	
		
		
		//None
		else
			return commands.UNDEFINED;
	}
	
}